<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>学生管理</title>
<script type="text/javascript" src="js/jquery-3.5.1.min.js"></script>
</head>
<jsp:include page="Teacher_header.jsp"></jsp:include>
<body>
	<h3>单次添加学生：</h3>
	<form action="TeacherServlet" method="post">
		<input type="hidden" name="method" value="addStudent" />
		<p>学号：</p><input type="text" name="number" />
		<p>姓名：</p><input type="text" name="name" />
		<p>密码：</p><input type="password" name="password" />
		<input type="submit" value="添加" />
	</form>
	<h3>批量excel添加学生：</h3>
	<form action="TeacherServlet" method="post"  enctype="multipart/form-data">
		<input type="hidden" name="method" value="addStudentByExcel" />
		<input type="file" name="excelImport"/>
		<input type="submit" value="批量添加" />
	</form>
	<h3>学生列表：</h3>
	<table>
		<thead>
			<tr>
				<th>学号</th>
				<th>姓名</th>
			</tr>
		</thead>
		<tbody id="tbd">
			
		</tbody>
	</table>
</body>
<script>
	$(function(){
		getStudentList();
	})
	
	function getStudentList(){
		$.ajax({
			url : "${pageContext.request.contextPath}/TeacherServlet",
			type : "GET",
			data : {"method":"listStudent"},
			dataType : "json",
			success : function(data) {
				var tbody = document.getElementById('tbd');
				for (var i = 0; i < data.length; ++i) {
					var tr = document.createElement('tr');
					tbody.appendChild(tr);
					for ( var k in data[i]) {
						var td = document.createElement('td');
						tr.appendChild(td);
						td.innerHTML = data[i][k];
					}
				}
			},
			error : function() {
				alert('获取学生信息失败！');
			}
		});
	}
</script>
</html>